package com.example.gateway.exception;

import com.example.common.dto.base.ResultMsg;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理认证异常
    @ExceptionHandler(AuthException.class)
    public ResultMsg<?> handleAuthException(AuthException ex) {
        return ResultMsg.generateFailResults400(ex.getMessage());
    }

    // 处理其他异常（兜底）
    @ExceptionHandler(Exception.class)
    public ResultMsg<?> handleException(Exception ex) {
        ex.printStackTrace();
        return ResultMsg.generateFailResults500("服务器内部错误: " + ex.getMessage());
    }
}
